/**
 * 2025/01/01 - 2025/12/31
 */
package com.snail.server.database.engine.dml.controller;

import com.snail.server.database.engine.dml.dto.DataInsertDTO;
import com.snail.server.database.engine.dml.dto.DataUpdateDTO;
import com.snail.server.database.engine.dml.manager.DMLManager;
import com.snail.server.database.engine.dml.vo.DataVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author zgadmin
 * @date 2025/9/8 17:10
 */
@Api(tags = "数据定义管理")
@RestController
@RequestMapping("/ddl/data-source/{dataSourceId}/table/{tableId}/data")
public class DDLController {

    @Resource
    DMLManager dmlManager;

    @ApiOperation("添加数据")
    @PostMapping
    public boolean insert(@PathVariable("dataSourceId") Long dataSourceId, @PathVariable("tableId") Long tableId, @RequestBody DataInsertDTO insert) {
        return dmlManager.insert(dataSourceId, tableId, insert);
    }

    @ApiOperation("修改数据")
    @PutMapping("/{dataId}")
    public boolean update(@PathVariable("dataSourceId") Long dataSourceId, @PathVariable("tableId") Long tableId, @PathVariable("dataId") Long dataId, @RequestBody DataUpdateDTO update) {
        return dmlManager.update(dataSourceId, tableId, dataId, update);
    }

    @ApiOperation("删除数据")
    @DeleteMapping("/{dataId}")
    public boolean deleteById(@PathVariable("dataSourceId") Long dataSourceId, @PathVariable("tableId") Long tableId, @PathVariable("dataId") Long dataId) {
        return dmlManager.deleteById(dataSourceId, tableId, dataId);
    }

    @ApiOperation("查询数据")
    @GetMapping("/{dataId}")
    public DataVO queryById(@PathVariable("dataSourceId") Long dataSourceId, @PathVariable("tableId") Long tableId, @PathVariable("dataId") Long dataId) {
        return dmlManager.queryById(dataSourceId, tableId, dataId);
    }

}